package cn.springcloud.fix.common.core.base;

import lombok.Builder;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@ToString
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private int code;

    private T data;

    private String message = "success";

    private Result(int code, String message, T data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public static <T> Result<T> SUCCESS() {
        return new Result<>(0, "操作成功", null);
    }

    public static <T> Result<T> SUCCESS(String message) {
        return new Result<>(0, message, null);
    }

    public static <T> Result<T> BUILD(T data) {
        return new Result<>(0, "操作成功", data);
    }

    public static <T> Result<T> SUCCESS(T data, String message) {
        return new Result<>(0, message, data);
    }

    public static <T> Result<T> ERROR(String message) {
        return new Result<>(-1, message, null);
    }

    public static <T> Result<T> ERROR(int code, String message) {
        return new Result<>(code, message, null);
    }
}

